package Task5;

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNextInt()){
           int size = scanner.nextInt();
           int[] arr = new int[size];
            for (int i = 0; i < arr.length; i++) {
                arr[i] = scanner.nextInt();
            }
           //用来存放子数组的和
           int sum = arr[0];
           //存放子数组最大和
            int max = arr[0];
            for (int i = 1; i < arr.length; i++) {
                //求连续数组的最大和
                sum = getMax(sum + arr[i],arr[i]);
                if(sum >= max ){
                    max = sum;
                }
            }
            System.out.println(max);
        }
    }

    private static int getMax(int i, int i1) {
        return i > i1 ? i : i1;
    }
}
